package com.example.demo.mapper;

import com.example.demo.entity.Comment;
import com.example.demo.entity.Open;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface CommentMapper {

    @Select("SELECT * FROM COMMENT WHERE commentid=#{id}")
    public List<Comment> findCommentOne(int id);

    @Select("select * from comment where ideaid=#{ideaid}")
    @Results({
            @Result(column = "openid",property = "openid"),
            @Result(column = "ideaid",property = "ideaid"),
            @Result(column = "contentdetails",property = "contentdetails"),
            @Result(column = "commentdata",property = "commentdata"),
            @Result(
                    property = "open",
                    javaType = Open.class,
                    column = "openid",
                    one=@One(select ="com.example.demo.mapper.OpenMapper.findOpenid")
            ),
    })
    public List<Comment> findCommentByIdeaid(int ideaid);

    //添加评论
    @Insert("insert into comment(ideaid,openid,contentdetails,commentdata)" +
            "value(#{ideaid},#{openid},#{contentdetails},#{commentdata})")
    public int InsertComment(Comment comment);

    @Delete("delete from comment where commentid=#{commentid}")
    public int DeleteComment(int commentid);


}
